home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Sound / EnableSoundThrough / EnableSoundThrough.p < prev    next >
Encoding:
Text File  |  1994-09-16  |  2.3 KB  |  77 lines  |  [TEXT/PJMM]

  1.  
  2. PROGRAM EnableSoundThrough;
  3. { Demonstrating how to enable input sound playthrough }
  4. { on a LC enabling playthrough kills sound output, on a si you can play back at the same time }
  5.  
  6.     CONST
  7.         siReadPermission = 0;                { permission passed to SPBOpenDevice }
  8.         siWritePermission = 1;
  9.         siPlayThruOnOff = 'plth';            { playthrough state for SPBGetDeviceInfo and SPBSetDeviceInfo }
  10.  
  11.     VAR
  12.         err: OSErr;
  13.         sInRef: LONGINT;
  14.         volume: Integer;
  15.  
  16. { These functions are declared in SoundInput.p (and equivalent files.) I am declaring them }
  17. { here for nothing sake, O.K.? }
  18.     FUNCTION SPBOpenDevice (deviceName: Str255; permission: INTEGER; VAR inRefNum: LONGINT): OSErr;
  19.     INLINE
  20.         $203C, $0518, $0014, $A800;
  21.  
  22.     FUNCTION SPBGetDeviceInfo (inRefNum: LONGINT; infoType: OSType; infoData: Ptr): OSErr;
  23.     INLINE
  24.         $203C, $0638, $0014, $A800;
  25.  
  26.     FUNCTION SPBSetDeviceInfo (inRefNum: LONGINT; infoType: OSType; infoData: Ptr): OSErr;
  27.     INLINE
  28.         $203C, $063C, $0014, $A800;
  29.  
  30.     FUNCTION SPBCloseDevice (inRefNum: LONGINT): OSErr;
  31.     INLINE
  32.         $203C, $021C, $0014, $A800;
  33.  
  34.     PROCEDURE GetPlayThroughVolume;
  35.     BEGIN
  36.         err := SPBGetDeviceInfo(sInRef, siPlayThruOnOff, @volume); { What is the current volume? }
  37.         IF err = noErr THEN
  38.             writeln('no problem getting play through volume =', volume)
  39.         ELSE
  40.             writeln('could not get play through volume, err = ', err);
  41.     END;
  42.  
  43.     PROCEDURE OnOffSoundThrough;
  44.     BEGIN
  45.         IF volume = 0 THEN { If playthrough volume is 0 (off) then we turn it on }
  46.             volume := 5
  47.         ELSE                    { if we have sound comming in we will kill it }
  48.             volume := 0;
  49.         err := SPBSetDeviceInfo(sInRef, siPlayThruOnOff, @volume);
  50.         IF err = noErr THEN
  51.             writeln('no problem setting play through, volume is ', volume)
  52.         ELSE
  53.             writeln('could not set play through, err = ', err)
  54.     END;
  55.  
  56. BEGIN
  57.     ShowText;
  58.     err := SPBOpenDevice('', siWritePermission, sInRef); { Null string means default device }
  59.     IF err = noErr THEN
  60.         BEGIN
  61.             writeln('No problem opening device');
  62.             GetPlayThroughVolume;                        { get current level         }
  63.             OnOffSoundThrough;                            { flip it                    }
  64.             GetPlayThroughVolume;                        { make sure it worked     }
  65.         END
  66.     ELSE
  67.         WriteLn('Problem when calling SPBOpenDevice, err = ', err);
  68.     WHILE NOT button DO
  69.         ;
  70.     IF sInRef <> 0 THEN
  71.         BEGIN
  72.             OnOffSoundThrough;    { flip it                    }
  73.             err := SPBCloseDevice(sInRef); { We opened it so lets close it }
  74.             IF err <> noErr THEN
  75.                 DebugStr('Error closing the input device');
  76.         END;
  77. END.